
package com.ruoyi.info.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.info.vo.AuditingEnterpriseBase;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.info.domain.CaseInfo;
import com.ruoyi.info.service.ICaseInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 案例信息Controller
 * 
 * @author wangshi
 * @date 2023-06-08
 */
@RestController
@RequestMapping("/info/caseInfo")
public class CaseInfoController extends BaseController
{
    @Autowired
    private ICaseInfoService caseInfoService;

    /**
     * 查询案例信息列表
     */
    @PreAuthorize("@ss.hasPermi('info:caseInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(CaseInfo caseInfo)
    {
        startPage();
        List<CaseInfo> list = caseInfoService.selectCaseInfoList(caseInfo);
        return getDataTable(list);
    }

    /**
     * 导出案例信息列表
     */
    @PreAuthorize("@ss.hasPermi('info:caseInfo:export')")
    @Log(title = "案例信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaseInfo caseInfo) throws IOException {
        caseInfoService.exportCaseInfo(response,caseInfo);
//        List<CaseInfo> list = caseInfoService.selectCaseInfoList(caseInfo);
//        ExcelUtil<CaseInfo> util = new ExcelUtil<CaseInfo>(CaseInfo.class);
//        util.exportExcel(response, list, "案例信息数据");
    }

    /**
     * 导出企业基地 批量导入模板
     */
    @PreAuthorize("@ss.hasPermi('info:caseInfo:templateDownload')")
    @Log(title = "案例信息", businessType = BusinessType.EXPORT)
    @PostMapping("/template/download")
    public void templateDownload(HttpServletResponse response) throws IOException {
        caseInfoService.templateDownload(response);
    }
    /**
     * 导入企业基地信息 模板导入
     */
    @PreAuthorize("@ss.hasPermi('info:caseInfo:templateRender')")
    @Log(title = "案例信息", businessType = BusinessType.EXPORT)
    @PostMapping("/template/render")
    public AjaxResult templateRender(MultipartFile file) throws IOException {
        return toAjax(caseInfoService.templateRender(file));
    }

    /**
     * 获取案例信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('info:caseInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(caseInfoService.selectCaseInfoById(id));
    }

    /**
     * 新增案例信息
     */
    @PreAuthorize("@ss.hasPermi('info:caseInfo:add')")
    @Log(title = "案例信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaseInfo caseInfo)
    {
        return toAjax(caseInfoService.insertCaseInfo(caseInfo));
    }

    /**
     * 修改案例信息
     */
    @PreAuthorize("@ss.hasPermi('info:caseInfo:edit')")
    @Log(title = "案例信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CaseInfo caseInfo)
    {
        return toAjax(caseInfoService.updateCaseInfo(caseInfo));
    }

    /**
     * 删除案例信息
     */
    @PreAuthorize("@ss.hasPermi('info:caseInfo:remove')")
    @Log(title = "案例信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(caseInfoService.deleteCaseInfoByIds(ids));
    }


    /**
     * 案例审核
     * @param auditingEnterpriseBase 案例审核字段
     * @return
     */
    @PreAuthorize("@ss.hasPermi('info:caseinfo:auditing')")
    @Log(title = "案例审核", businessType = BusinessType.UPDATE)
    @PostMapping("/auditing")
    public AjaxResult auditing(@RequestBody AuditingEnterpriseBase auditingEnterpriseBase){
        auditingEnterpriseBase.setCreateBy(getUsername());
        return toAjax(caseInfoService.auditingCaseInfo(auditingEnterpriseBase));
    }

}
